package com.lc202406;

import java.util.HashMap;

public class Solution383 {
    public boolean canConstruct(String ransomNote, String magazine) {
        HashMap<Character, Integer> count = new HashMap<>();
        for (int i = 0; i < magazine.length(); i++) {
            char key = magazine.charAt(i);
            Integer cnt = count.getOrDefault(key, 0) + 1;
            count.put(key, cnt);
        }
        for (int i = 0; i < ransomNote.length(); i++) {
            char key = ransomNote.charAt(i);
            int cnt = count.getOrDefault(key, 0) - 1;
            if (cnt < 0) {
                return false;
            }
            count.put(key, cnt);
        }
        return true;
    }
}
